﻿using An_Im.Core;
using An_Im.Expression;
using System;
using System.Collections.Generic;
using System.DirectoryServices.ActiveDirectory;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

using PPT = Microsoft.Office.Interop.PowerPoint;

namespace An_Im.UI
{

    enum AnimPropertyType
    {
        Visibility, Color, Other
    }

    /// <summary>
    /// 不采用 MVVM 而使用手动硬绑定来实现数据的监听（因为Office的COM模型存在这样或那样的问题）
    /// </summary>
    public partial class AnImStormControl : UserControl
    {
        #region static ui config

        /// <summary>
        /// 左侧空间的宽度。
        /// </summary>
        public static GridLength LeftSpaceWidth = new GridLength(80d);

        /// <summary>
        /// 右侧空间的宽度
        /// </summary>
        public static GridLength MidSpaceWidth = new GridLength(80d);

        /// <summary>
        /// 右侧空间的宽度
        /// </summary>
        public static GridLength RightSpaceWidth = new GridLength(80d);


        #endregion

        #region temp fields
        private bool isInControl = false;
        private bool effectBarGroupEventFlag = false; // 如果 flag 为 true 时不执行事件。
        private bool behaviorBarGroupEventFlag = false; // 如果 flag 为 true 时不执行事件。

        private Dictionary<PPT.MsoAnimType, FrameworkElement> _animTypeUIDic;// 不同类型的动画效果对应不同的面板。
        #endregion

        #region ctor
        public AnImStormControl()
        {
            InitializeComponent();
            InitMainUI();
            InitEffectListUI();
            InitEffectTimingUI();
            InitBehaviorListUI();
            InitBehaviorTimingUI();
            InitBehaviorInformationUI();
        }

        private void InitMainUI()
        {
            this.MouseEnter += (s, e) => { GlobalMessageStateUpdater.StopListen(); isInControl = true; };
            this.MouseLeave += (s, e) => { GlobalMessageStateUpdater.ContinueListen(); isInControl = false; };

            // 序列变化监听事件。
            GlobalMessageStateUpdater.SequenceChanged += (s, e) => { RefreshTaskPane(); };

            CoreManipulator.App.WindowSelectionChange += (sel) =>
            {
                try
                {
                    if (isInControl == true) return;
                    if (sel.Type == PPT.PpSelectionType.ppSelectionShapes)
                    {
                        var hashset = new HashSet<PPT.Shape>();
                        var shprange = sel.ShapeRange;
                        foreach (PPT.Shape shp in sel.ShapeRange)
                        {
                            hashset.Add(shp);
                        }

                        var sld = shprange.Parent as PPT.Slide;


                        effectList.SelectedItems.Clear();
                        foreach (PPT.Effect eff in effectList.Items)
                        {
                            if (hashset.Contains(eff.Shape))
                                effectList.SelectedItems.Add(eff);
                        }

                    }
                }
                catch
                {

                }
                
            };

        }

        private void InitEffectListUI()
        {
            singleLikeButton.Click += (s, e) =>
            {
                var efflist = new List<PPT.Effect>();
                efflist.AddRange(EffectRange);
                CustomAnimationLib.AddRange(CustomAnimationLib.GetEffectInfomations(EffectRange, false, null));
            };

            groupLikeButton.Click += (s, e) =>
            {
                if (EffectRange.Count() == 0) return;
                CustomAnimationLib.Add(CoreManipulator.RecordGroupEffect(CustomAnimationLib.GetEffectInfomations(EffectRange, false, null), "组合" + new Random().Next(1000, 9999), null, null));
            };

            selectShapeButton.Click += (s, e) =>
            {
                if (isInControl == false) return;
                var sld = CoreManipulator.GetSlideInGeneralOccassion();
                if (sld == null) return;
                var hashset = new HashSet<PPT.Shape>();
                foreach (var eff in EffectRange)
                {
                    hashset.Add(eff.Shape);
                }
                var flag = 1;
                foreach (var shp in hashset)
                {
                    if (flag == 1)
                    {
                        flag = 0;
                        shp.Select(Microsoft.Office.Core.MsoTriState.msoTrue);
                    }
                    else
                    {
                        shp.Select(Microsoft.Office.Core.MsoTriState.msoFalse);
                    }

                }
            };

            likeButton.Click += (s, e) =>
            {
                var efflist = new List<PPT.Effect>();
                efflist.AddRange(EffectRange);
                CustomAnimationLib.AddRange(CustomAnimationLib.GetEffectInfomations(EffectRange, false, null));
            };

            groupButton.Click += (s, e) =>
            {
                if (EffectRange.Count() == 0) return;
                CustomAnimationLib.Add(CoreManipulator.RecordGroupEffect(CustomAnimationLib.GetEffectInfomations(EffectRange, false, null), "组合" + new Random().Next(1000, 9999), null, null));
            };

            deleteEffectButton.Click += (s, e) =>
            {
                var efflist = new List<PPT.Effect>();
                efflist.AddRange(EffectRange);
                foreach (var item in efflist)
                {
                    item.Delete();
                }
                RefreshTaskPane();
            };

            effectList.KeyDown += (s, e) =>
            {
                if (e.Key == Key.Delete)
                {
                    var efflist = new List<PPT.Effect>();
                    efflist.AddRange(EffectRange);
                    foreach (var item in efflist)
                    {
                        item.Delete();
                    }
                    RefreshTaskPane();
                }
            };




            //triggerStyleButton1_Mouse.Click += (s, e) =>
            //{
            //    foreach (var eff in EffectRange)
            //    {
            //        eff.Timing.TriggerType = PPT.MsoAnimTriggerType.msoAnimTriggerOnPageClick;
            //    }
            //};

            //triggerStyleButton2_Before.Click += (s, e) =>
            //{
            //    foreach (var eff in EffectRange)
            //    {
            //        eff.Timing.TriggerType = PPT.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
            //    }
            //};

            //triggerStyleButton3_After.Click += (s, e) =>
            //{
            //    foreach (var eff in EffectRange)
            //    {
            //        eff.Timing.TriggerType = PPT.MsoAnimTriggerType.msoAnimTriggerAfterPrevious;
            //    }
            //};


        }

        private void InitEffectTimingUI()
        {
            #region init
            effectDelayBox.OnlyNumber = true;
            effectDelayBox.EmptyReplaceString = "0";
            effectDelayBox.MinValue = 0; effectDelayBox.MaxValue = 65535;
            effectDelayBox.ButtonText1 = "↑a";
            effectDelayBox.ButtonText2 = "↓a";
            effectDelayBox.ButtonText3 = "↑r";
            effectDelayBox.ButtonText4 = "↓r";

            effectDurationBox.OnlyNumber = true;
            effectDurationBox.EmptyReplaceString = "0.5";
            effectDurationBox.MinValue = 0.01f; effectDurationBox.MaxValue = 65535f;
            effectDurationBox.ButtonText1 = "↑a";
            effectDurationBox.ButtonText2 = "↓a";
            effectDurationBox.ButtonText3 = "↑r";
            effectDurationBox.ButtonText4 = "↓r";

            effectRepeatBox.OnlyNumber = true; effectRepeatBox.EmptyReplaceString = "1";
            effectRepeatBox.MinValue = 1; effectRepeatBox.MaxValue = 999;
            effectRepeatBox.ButtonText1 = "∞";
            effectRepeatBox.ButtonText2 = "1";

            effectSmoothStartBox.OnlyNumber = true; effectSmoothStartBox.EmptyReplaceString = "0";
            effectSmoothStartBox.LargeChange = 0.05f; effectSmoothStartBox.SmallChange = 0.01f;
            effectSmoothStartBox.MinValue = 0; effectSmoothStartBox.MaxValue = 1;
            effectSmoothStartBox.ButtonText1 = "↑a";
            effectSmoothStartBox.ButtonText2 = "↓a";
            effectSmoothStartBox.ButtonText3 = "↑r";
            effectSmoothStartBox.ButtonText4 = "↓r";


            effectSmoothEndBox.OnlyNumber = true; effectSmoothEndBox.EmptyReplaceString = "0";
            effectSmoothStartBox.LargeChange = 0.05f; effectSmoothEndBox.SmallChange = 0.01f;
            effectSmoothEndBox.MinValue = 0; effectSmoothEndBox.MaxValue = 1;
            effectSmoothEndBox.ButtonText1 = "↑a";
            effectSmoothEndBox.ButtonText2 = "↓a";
            effectSmoothEndBox.ButtonText3 = "↑r";
            effectSmoothEndBox.ButtonText4 = "↓r";

            effectBounceEndBox.OnlyNumber = true; effectBounceEndBox.EmptyReplaceString = "0";
            effectBounceEndBox.LargeChange = 0.05f; effectBounceEndBox.SmallChange = 0.01f;
            effectBounceEndBox.MinValue = 0; effectBounceEndBox.MaxValue = 1;
            effectBounceEndBox.ButtonText1 = "↑a";
            effectBounceEndBox.ButtonText2 = "↓a";
            effectBounceEndBox.ButtonText3 = "↑r";
            effectBounceEndBox.ButtonText4 = "↓r";

            #endregion

            #region effectDelayBox

            effectDelayBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDelayBox.LargeChange;
                if (ispress)
                    change = effectDelayBox.SmallChange;
                var val = float.Parse(effectDelayBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Min(effectDelayBox.MaxValue, val + change);

                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.TriggerDelayTime = val;
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDelayBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDelayBox.LargeChange;
                if (ispress)
                    change = effectDelayBox.SmallChange;
                var val = float.Parse(effectDelayBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Max(effectDelayBox.MinValue, val - change);

                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.TriggerDelayTime = val;
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDelayBox.IncreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDelayBox.LargeChange;
                if (ispress)
                    change = effectDelayBox.SmallChange;
                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.TriggerDelayTime = Math.Min(eff.Timing.TriggerDelayTime + change, effectDelayBox.MaxValue);
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDelayBox.DecreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDelayBox.LargeChange;
                if (ispress)
                    change = effectDelayBox.SmallChange;
                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.TriggerDelayTime = Math.Max(eff.Timing.TriggerDelayTime - change, effectDelayBox.MinValue);
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDelayBox.InputFinished += (sender, arg) =>
            {
                foreach (var eff in EffectRange)
                {
                    eff.Timing.TriggerDelayTime = float.Parse(effectDelayBox.Text);
                }
            };

            #endregion

            #region effectDurationBox

            effectDurationBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDurationBox.LargeChange;
                if (ispress) change = effectDurationBox.SmallChange;
                var val = float.Parse(effectDurationBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Min(effectDurationBox.MaxValue, val + change);

                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.Duration = val;
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDurationBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDurationBox.LargeChange;
                if (ispress)
                    change = effectDurationBox.SmallChange;
                var val = float.Parse(effectDurationBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Max(effectDurationBox.MinValue, val - change);

                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.Duration = val;
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDurationBox.IncreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDurationBox.LargeChange;
                if (ispress)
                    change = effectDurationBox.SmallChange;
                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.Duration = Math.Min(eff.Timing.Duration + change, effectDurationBox.MaxValue);
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDurationBox.DecreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectDurationBox.LargeChange;
                if (ispress)
                    change = effectDurationBox.SmallChange;
                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.Duration = Math.Max(eff.Timing.Duration - change, effectDurationBox.MinValue);
                }
                UpdateEffectTimingUI(effrange);
            };

            effectDurationBox.InputFinished += (sender, arg) =>
            {
                foreach (var eff in EffectRange)
                {
                    eff.Timing.Duration = float.Parse(effectDurationBox.Text);
                }
            };

            #endregion

            #region effectRepeatBox

            // 此处为将全体动画的重复置为999
            effectRepeatBox.IncreaseAbsValue += (s, e) =>
            {
                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.RepeatCount = 999;
                }
                UpdateEffectTimingUI(effrange);
            };

            effectRepeatBox.DecreaseAbsValue += (s, e) =>
            {
                var effrange = EffectRange;
                foreach (var eff in effrange)
                {
                    eff.Timing.RepeatCount = 1;
                }
                UpdateEffectTimingUI(effrange);
            };

            effectRepeatBox.InputFinished += (sender, arg) =>
            {
                var val = (int)float.Parse(effectRepeatBox.Text);
                effectRepeatBox.Text = val.ToString();
                foreach (var eff in EffectRange)
                {
                    eff.Timing.RepeatCount = val;
                }
            };

            #endregion

            #region effectSmooth

            effectSmoothStartBox.InputFinished += (sender, arg) =>
            {
                var startval = float.Parse(effectSmoothStartBox.Text);
                var endval = float.Parse(effectSmoothEndBox.Text);
                var bncval = float.Parse(effectBounceEndBox.Text);
                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                }

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothEndBox.InputFinished += (sender, arg) =>
            {
                var endval = float.Parse(effectSmoothEndBox.Text);
                var startval = float.Parse(effectSmoothStartBox.Text);
                var bncval = 0f;

                startval = Math.Min(1f - endval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectBounceEndBox.InputFinished += (sender, arg) =>
            {
                var startval = float.Parse(effectSmoothStartBox.Text);
                var bncval = float.Parse(effectBounceEndBox.Text);
                var endval = 0f;

                startval = Math.Min(1f - bncval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            #region abs
            effectSmoothStartBox.IncreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(effectSmoothStartBox.Text);
                var endval = float.Parse(effectSmoothEndBox.Text);
                var bncval = float.Parse(effectBounceEndBox.Text);
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothStartBox.LargeChange;
                var minval = effectSmoothStartBox.MinValue;
                var maxval = effectSmoothStartBox.MaxValue;
                if (ispress) change = effectSmoothStartBox.SmallChange;

                startval = Math.Min(startval + change, maxval);

                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                }

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothEndBox.IncreaseAbsValue += (sender, arg) =>
            {
                var endval = float.Parse(effectSmoothEndBox.Text);
                var startval = float.Parse(effectSmoothStartBox.Text);
                var bncval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothEndBox.LargeChange;
                var minval = effectSmoothEndBox.MinValue;
                var maxval = effectSmoothEndBox.MaxValue;
                if (ispress) change = effectSmoothEndBox.SmallChange;

                endval = Math.Min(maxval, endval + change);
                startval = Math.Min(1f - endval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }

            };

            effectBounceEndBox.IncreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(effectSmoothStartBox.Text);
                var bncval = float.Parse(effectBounceEndBox.Text);
                var endval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectBounceEndBox.LargeChange;
                var minval = effectBounceEndBox.MinValue;
                var maxval = effectBounceEndBox.MaxValue;
                if (ispress) change = effectBounceEndBox.SmallChange;

                bncval = Math.Min(maxval, bncval + change);

                startval = Math.Min(1f - bncval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothStartBox.DecreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(effectSmoothStartBox.Text);
                var endval = float.Parse(effectSmoothEndBox.Text);
                var bncval = float.Parse(effectBounceEndBox.Text);
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothStartBox.LargeChange;
                var minval = effectSmoothStartBox.MinValue;
                var maxval = effectSmoothStartBox.MaxValue;
                if (ispress) change = effectSmoothStartBox.SmallChange;

                startval = Math.Max(startval - change, minval);

                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                }

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothEndBox.DecreaseAbsValue += (sender, arg) =>
            {
                var endval = float.Parse(effectSmoothEndBox.Text);
                var startval = float.Parse(effectSmoothStartBox.Text);
                var bncval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothEndBox.LargeChange;
                var minval = effectSmoothEndBox.MinValue;
                var maxval = effectSmoothEndBox.MaxValue;
                if (ispress) change = effectSmoothEndBox.SmallChange;

                endval = Math.Max(minval, endval - change);
                startval = Math.Min(1f - endval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }

            };

            effectBounceEndBox.DecreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(effectSmoothStartBox.Text);
                var bncval = float.Parse(effectBounceEndBox.Text);
                var endval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectBounceEndBox.LargeChange;
                var minval = effectBounceEndBox.MinValue;
                var maxval = effectBounceEndBox.MaxValue;
                if (ispress) change = effectBounceEndBox.SmallChange;

                bncval = Math.Max(minval, bncval - change);

                startval = Math.Min(1f - bncval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };
            #endregion

            #region rel
            effectSmoothStartBox.IncreaseRelValue += (sender, arg) =>
            {
                bool firstflag = false;
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothStartBox.LargeChange;
                var minval = effectSmoothStartBox.MinValue;
                var maxval = effectSmoothStartBox.MaxValue;
                if (ispress) change = effectSmoothStartBox.SmallChange;

                foreach (var eff in EffectRange)
                {
                    var tim = eff.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    startval = Math.Min(startval + change, maxval);

                    if (endval == 0f) // 处于弹性结束
                    {
                        bncval = Math.Min(1f - startval, bncval);
                    }
                    else if (bncval == 0f)// 处于平滑结束
                    {
                        endval = Math.Min(1f - startval, endval);
                    }
                    if (firstflag == false)
                        SetEffectTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;


                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothEndBox.IncreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothEndBox.LargeChange;
                var minval = effectSmoothEndBox.MinValue;
                var maxval = effectSmoothEndBox.MaxValue;
                if (ispress) change = effectSmoothEndBox.SmallChange;

                foreach (var eff in EffectRange)
                {
                    var tim = eff.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;
                    endval = Math.Min(maxval, endval + change);
                    startval = Math.Min(1f - endval, startval);

                    if (firstflag == false)
                        SetEffectTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }

            };

            effectBounceEndBox.IncreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectBounceEndBox.LargeChange;
                var minval = effectBounceEndBox.MinValue;
                var maxval = effectBounceEndBox.MaxValue;
                if (ispress) change = effectBounceEndBox.SmallChange;

                foreach (var eff in EffectRange)
                {
                    var tim = eff.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    bncval = Math.Min(maxval, bncval + change);

                    startval = Math.Min(1f - bncval, startval);

                    if (firstflag == false)
                        SetEffectTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothStartBox.DecreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothStartBox.LargeChange;
                var minval = effectSmoothStartBox.MinValue;
                var maxval = effectSmoothStartBox.MaxValue;
                if (ispress) change = effectSmoothStartBox.SmallChange;



                foreach (var eff in EffectRange)
                {
                    var tim = eff.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    startval = Math.Max(startval - change, minval);

                    if (endval == 0f) // 处于弹性结束
                    {
                        bncval = Math.Min(1f - startval, bncval);
                    }
                    else if (bncval == 0f)// 处于平滑结束
                    {
                        endval = Math.Min(1f - startval, endval);
                    }

                    if (firstflag == false)
                        SetEffectTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothEndBox.DecreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectSmoothEndBox.LargeChange;
                var minval = effectSmoothEndBox.MinValue;
                var maxval = effectSmoothEndBox.MaxValue;
                if (ispress) change = effectSmoothEndBox.SmallChange;

                foreach (var eff in EffectRange)
                {
                    var tim = eff.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    endval = Math.Max(minval, endval - change);
                    startval = Math.Min(1f - endval, startval);

                    if (firstflag == false)
                        SetEffectTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }

            };

            effectBounceEndBox.DecreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = effectBounceEndBox.LargeChange;
                var minval = effectBounceEndBox.MinValue;
                var maxval = effectBounceEndBox.MaxValue;
                if (ispress) change = effectBounceEndBox.SmallChange;

                foreach (var eff in EffectRange)
                {
                    var tim = eff.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    bncval = Math.Max(minval, bncval - change);
                    startval = Math.Min(1f - bncval, startval);

                    if (firstflag == false)
                        SetEffectTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };
            #endregion



            effectSmoothStartBar.ValueChanged += (sender, arg) =>
            {
                if (effectBarGroupEventFlag) return;
                var startval = (float)effectSmoothStartBar.Value;
                var endval = (float)effectSmoothEndBar.Value;
                var bncval = (float)effectBounceEndBar.Value;
                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                    effectBounceEndBar.Value = bncval;
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                    effectSmoothEndBar.Value = endval;
                }

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectSmoothEndBar.ValueChanged += (sender, arg) =>
            {
                if (effectBarGroupEventFlag) return;
                var endval = (float)effectSmoothEndBar.Value;
                var startval = (float)effectSmoothStartBar.Value;
                var bncval = 0f;

                startval = Math.Min(1f - endval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };

            effectBounceEndBar.ValueChanged += (sender, arg) =>
            {
                if (effectBarGroupEventFlag) return;
                var bncval = (float)effectBounceEndBar.Value;
                var endval = 0f;
                var startval = (float)effectSmoothStartBar.Value;


                startval = Math.Min(1f - bncval, startval);

                SetEffectTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var eff in EffectRange)
                {
                    eff.Timing.Accelerate = startval;
                    eff.Timing.Decelerate = endval;
                    eff.Timing.BounceEndIntensity = bncval;
                }
            };
            #endregion

            #region effectAutoReverse

            effectAutoReverseCheckBox.Checked += (sender, arg) =>
            {
                foreach (var eff in EffectRange)
                {
                    eff.Timing.AutoReverse = Microsoft.Office.Core.MsoTriState.msoTrue;
                }
            };

            effectAutoReverseCheckBox.Unchecked += (sender, arg) =>
            {
                foreach (var eff in EffectRange)
                {
                    eff.Timing.AutoReverse = Microsoft.Office.Core.MsoTriState.msoFalse;
                }
            };


            #endregion

            #region triggerType
            effectTriggerTypeComboBox.SelectionChanged += (s, e) =>
            {
                int itemid = effectTriggerTypeComboBox.SelectedIndex;
                PPT.MsoAnimTriggerType triggerType;
                if (itemid == 0)
                    triggerType = PPT.MsoAnimTriggerType.msoAnimTriggerOnPageClick;
                else if (itemid == 1)
                    triggerType = PPT.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
                else if (itemid == 2)
                    triggerType = PPT.MsoAnimTriggerType.msoAnimTriggerAfterPrevious;
                else
                    return;

                foreach (var eff in EffectRange)
                {
                    eff.Timing.TriggerType = triggerType;
                }
            };
            #endregion


        }

        private void InitBehaviorListUI()
        {


            // 添加设置效果
            behaviorListAddSetBehavior.Click += (sender, e) =>
            {
                var effects = EffectRange;
                if (effects == null) return;
                var effect = effects.First();
                var behaviors = effect.Behaviors;
                var behavior = behaviors.Add(PPT.MsoAnimType.msoAnimTypeSet);
                behavior.SetEffect.Property = PPT.MsoAnimProperty.msoAnimX;
                UpdateBehaviorList();
            };

            // 添加属性效果
            behaviorListAddPropertyBehavior.Click += (sender, e) =>
            {
                var effects = EffectRange;
                if (effects == null) return;
                var effect = effects.First();
                var behaviors = effect.Behaviors;
                var behavior = behaviors.Add(PPT.MsoAnimType.msoAnimTypeProperty);
                behavior.PropertyEffect.Property = PPT.MsoAnimProperty.msoAnimX;
                UpdateBehaviorList();
            };

            // 添加属性效果
            behaviorListRemoveBehavior.Click += (sender, e) =>
            {
                var effects = EffectRange;
                var behaviorRange = BehaviorRange;
                if (effects == null) return;
                var effect = effects.First();
                var behaviors = BehaviorRange;
                if (effect.Behaviors.Count != behaviors.Count())
                    foreach (var bhv in behaviors)
                    {
                        bhv.Delete();
                    }
                UpdateBehaviorList();
            };
        }

        private void InitBehaviorTimingUI()
        {
            #region init
            behaviorDelayBox.OnlyNumber = true;
            behaviorDelayBox.EmptyReplaceString = "0";
            behaviorDelayBox.MinValue = 0; behaviorDelayBox.MaxValue = 65535;
            behaviorDelayBox.ButtonText1 = "↑a";
            behaviorDelayBox.ButtonText2 = "↓a";
            behaviorDelayBox.ButtonText3 = "↑r";
            behaviorDelayBox.ButtonText4 = "↓r";

            behaviorDurationBox.OnlyNumber = true;
            behaviorDurationBox.EmptyReplaceString = "0.5";
            behaviorDurationBox.MinValue = 0.01f; behaviorDurationBox.MaxValue = 65535f;
            behaviorDurationBox.ButtonText1 = "↑a";
            behaviorDurationBox.ButtonText2 = "↓a";
            behaviorDurationBox.ButtonText3 = "↑r";
            behaviorDurationBox.ButtonText4 = "↓r";

            behaviorRepeatBox.OnlyNumber = true; behaviorRepeatBox.EmptyReplaceString = "1";
            behaviorRepeatBox.MinValue = 1; behaviorRepeatBox.MaxValue = 999;
            behaviorRepeatBox.ButtonText1 = "∞";
            behaviorRepeatBox.ButtonText2 = "1";

            behaviorSmoothStartBox.OnlyNumber = true; behaviorSmoothStartBox.EmptyReplaceString = "0";
            behaviorSmoothStartBox.LargeChange = 0.05f; behaviorSmoothStartBox.SmallChange = 0.01f;
            behaviorSmoothStartBox.MinValue = 0; behaviorSmoothStartBox.MaxValue = 1;
            behaviorSmoothStartBox.ButtonText1 = "↑a";
            behaviorSmoothStartBox.ButtonText2 = "↓a";
            behaviorSmoothStartBox.ButtonText3 = "↑r";
            behaviorSmoothStartBox.ButtonText4 = "↓r";


            behaviorSmoothEndBox.OnlyNumber = true; behaviorSmoothEndBox.EmptyReplaceString = "0";
            behaviorSmoothStartBox.LargeChange = 0.05f; behaviorSmoothEndBox.SmallChange = 0.01f;
            behaviorSmoothEndBox.MinValue = 0; behaviorSmoothEndBox.MaxValue = 1;
            behaviorSmoothEndBox.ButtonText1 = "↑a";
            behaviorSmoothEndBox.ButtonText2 = "↓a";
            behaviorSmoothEndBox.ButtonText3 = "↑r";
            behaviorSmoothEndBox.ButtonText4 = "↓r";

            behaviorBounceEndBox.OnlyNumber = true; behaviorBounceEndBox.EmptyReplaceString = "0";
            behaviorBounceEndBox.LargeChange = 0.05f; behaviorBounceEndBox.SmallChange = 0.01f;
            behaviorBounceEndBox.MinValue = 0; behaviorBounceEndBox.MaxValue = 1;
            behaviorBounceEndBox.ButtonText1 = "↑a";
            behaviorBounceEndBox.ButtonText2 = "↓a";
            behaviorBounceEndBox.ButtonText3 = "↑r";
            behaviorBounceEndBox.ButtonText4 = "↓r";

            #endregion

            #region behaviorDelayBox

            behaviorDelayBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDelayBox.LargeChange;
                if (ispress)
                    change = behaviorDelayBox.SmallChange;
                var val = float.Parse(behaviorDelayBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Min(behaviorDelayBox.MaxValue, val + change);

                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.TriggerDelayTime = val;
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDelayBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDelayBox.LargeChange;
                if (ispress)
                    change = behaviorDelayBox.SmallChange;
                var val = float.Parse(behaviorDelayBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Max(behaviorDelayBox.MinValue, val - change);

                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.TriggerDelayTime = val;
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDelayBox.IncreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDelayBox.LargeChange;
                if (ispress)
                    change = behaviorDelayBox.SmallChange;
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.TriggerDelayTime = Math.Min(bhv.Timing.TriggerDelayTime + change, behaviorDelayBox.MaxValue);
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDelayBox.DecreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDelayBox.LargeChange;
                if (ispress)
                    change = behaviorDelayBox.SmallChange;
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.TriggerDelayTime = Math.Max(bhv.Timing.TriggerDelayTime - change, behaviorDelayBox.MinValue);
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDelayBox.InputFinished += (sender, arg) =>
            {
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.TriggerDelayTime = float.Parse(behaviorDelayBox.Text);
                }
            };

            #endregion

            #region behaviorDurationBox

            behaviorDurationBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDurationBox.LargeChange;
                if (ispress) change = behaviorDurationBox.SmallChange;
                var val = float.Parse(behaviorDurationBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Min(behaviorDurationBox.MaxValue, val + change);

                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.Duration = val;
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDurationBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDurationBox.LargeChange;
                if (ispress)
                    change = behaviorDurationBox.SmallChange;
                var val = float.Parse(behaviorDurationBox.Text);
                if (val <= 0.01f) val = 0;
                val = Math.Max(behaviorDurationBox.MinValue, val - change);

                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.Duration = val;
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDurationBox.IncreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDurationBox.LargeChange;
                if (ispress)
                    change = behaviorDurationBox.SmallChange;
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.Duration = Math.Min(bhv.Timing.Duration + change, behaviorDurationBox.MaxValue);
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDurationBox.DecreaseRelValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorDurationBox.LargeChange;
                if (ispress)
                    change = behaviorDurationBox.SmallChange;
                var bhvrange = BehaviorRange;

                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.Duration = Math.Max(bhv.Timing.Duration - change, behaviorDurationBox.MinValue);
                }

                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorDurationBox.InputFinished += (sender, arg) =>
            {
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Duration = float.Parse(behaviorDurationBox.Text);
                }
            };

            #endregion

            #region behaviorRepeatBox

            // 此处为将全体动画的重复置为999
            behaviorRepeatBox.IncreaseAbsValue += (s, e) =>
            {
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.RepeatCount = 999;
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorRepeatBox.DecreaseAbsValue += (s, e) =>
            {
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    bhv.Timing.RepeatCount = 1;
                }
                UpdateBehaviorTimingUI(bhvrange);
            };

            behaviorRepeatBox.InputFinished += (sender, arg) =>
            {
                var val = (int)float.Parse(behaviorRepeatBox.Text);
                behaviorRepeatBox.Text = val.ToString();
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.RepeatCount = val;
                }
            };

            #endregion

            #region behaviorSmooth

            behaviorSmoothStartBox.InputFinished += (sender, arg) =>
            {
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var endval = float.Parse(behaviorSmoothEndBox.Text);
                var bncval = float.Parse(behaviorBounceEndBox.Text);
                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                }

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothEndBox.InputFinished += (sender, arg) =>
            {
                var endval = float.Parse(behaviorSmoothEndBox.Text);
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var bncval = 0f;

                startval = Math.Min(1f - endval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorBounceEndBox.InputFinished += (sender, arg) =>
            {
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var bncval = float.Parse(behaviorBounceEndBox.Text);
                var endval = 0f;

                startval = Math.Min(1f - bncval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            #region abs
            behaviorSmoothStartBox.IncreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var endval = float.Parse(behaviorSmoothEndBox.Text);
                var bncval = float.Parse(behaviorBounceEndBox.Text);
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothStartBox.LargeChange;
                var minval = behaviorSmoothStartBox.MinValue;
                var maxval = behaviorSmoothStartBox.MaxValue;
                if (ispress) change = behaviorSmoothStartBox.SmallChange;

                startval = Math.Min(startval + change, maxval);

                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                }

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothEndBox.IncreaseAbsValue += (sender, arg) =>
            {
                var endval = float.Parse(behaviorSmoothEndBox.Text);
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var bncval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothEndBox.LargeChange;
                var minval = behaviorSmoothEndBox.MinValue;
                var maxval = behaviorSmoothEndBox.MaxValue;
                if (ispress) change = behaviorSmoothEndBox.SmallChange;

                endval = Math.Min(maxval, endval + change);
                startval = Math.Min(1f - endval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }

            };

            behaviorBounceEndBox.IncreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var bncval = float.Parse(behaviorBounceEndBox.Text);
                var endval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorBounceEndBox.LargeChange;
                var minval = behaviorBounceEndBox.MinValue;
                var maxval = behaviorBounceEndBox.MaxValue;
                if (ispress) change = behaviorBounceEndBox.SmallChange;

                bncval = Math.Min(maxval, bncval + change);

                startval = Math.Min(1f - bncval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothStartBox.DecreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var endval = float.Parse(behaviorSmoothEndBox.Text);
                var bncval = float.Parse(behaviorBounceEndBox.Text);
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothStartBox.LargeChange;
                var minval = behaviorSmoothStartBox.MinValue;
                var maxval = behaviorSmoothStartBox.MaxValue;
                if (ispress) change = behaviorSmoothStartBox.SmallChange;

                startval = Math.Max(startval - change, minval);

                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                }

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothEndBox.DecreaseAbsValue += (sender, arg) =>
            {
                var endval = float.Parse(behaviorSmoothEndBox.Text);
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var bncval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothEndBox.LargeChange;
                var minval = behaviorSmoothEndBox.MinValue;
                var maxval = behaviorSmoothEndBox.MaxValue;
                if (ispress) change = behaviorSmoothEndBox.SmallChange;

                endval = Math.Max(minval, endval - change);
                startval = Math.Min(1f - endval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }

            };

            behaviorBounceEndBox.DecreaseAbsValue += (sender, arg) =>
            {
                var startval = float.Parse(behaviorSmoothStartBox.Text);
                var bncval = float.Parse(behaviorBounceEndBox.Text);
                var endval = 0f;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorBounceEndBox.LargeChange;
                var minval = behaviorBounceEndBox.MinValue;
                var maxval = behaviorBounceEndBox.MaxValue;
                if (ispress) change = behaviorBounceEndBox.SmallChange;

                bncval = Math.Max(minval, bncval - change);

                startval = Math.Min(1f - bncval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };
            #endregion

            #region rel
            behaviorSmoothStartBox.IncreaseRelValue += (sender, arg) =>
            {
                bool firstflag = false;
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothStartBox.LargeChange;
                var minval = behaviorSmoothStartBox.MinValue;
                var maxval = behaviorSmoothStartBox.MaxValue;
                if (ispress) change = behaviorSmoothStartBox.SmallChange;

                foreach (var bhv in BehaviorRange)
                {
                    var tim = bhv.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    startval = Math.Min(startval + change, maxval);

                    if (endval == 0f) // 处于弹性结束
                    {
                        bncval = Math.Min(1f - startval, bncval);
                    }
                    else if (bncval == 0f)// 处于平滑结束
                    {
                        endval = Math.Min(1f - startval, endval);
                    }
                    if (firstflag == false)
                        SetBehaviorTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;


                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothEndBox.IncreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothEndBox.LargeChange;
                var minval = behaviorSmoothEndBox.MinValue;
                var maxval = behaviorSmoothEndBox.MaxValue;
                if (ispress) change = behaviorSmoothEndBox.SmallChange;

                foreach (var bhv in BehaviorRange)
                {
                    var tim = bhv.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;
                    endval = Math.Min(maxval, endval + change);
                    startval = Math.Min(1f - endval, startval);

                    if (firstflag == false)
                        SetBehaviorTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }

            };

            behaviorBounceEndBox.IncreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorBounceEndBox.LargeChange;
                var minval = behaviorBounceEndBox.MinValue;
                var maxval = behaviorBounceEndBox.MaxValue;
                if (ispress) change = behaviorBounceEndBox.SmallChange;

                foreach (var bhv in BehaviorRange)
                {
                    var tim = bhv.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    bncval = Math.Min(maxval, bncval + change);

                    startval = Math.Min(1f - bncval, startval);

                    if (firstflag == false)
                        SetBehaviorTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothStartBox.DecreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothStartBox.LargeChange;
                var minval = behaviorSmoothStartBox.MinValue;
                var maxval = behaviorSmoothStartBox.MaxValue;
                if (ispress) change = behaviorSmoothStartBox.SmallChange;



                foreach (var bhv in BehaviorRange)
                {
                    var tim = bhv.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    startval = Math.Max(startval - change, minval);

                    if (endval == 0f) // 处于弹性结束
                    {
                        bncval = Math.Min(1f - startval, bncval);
                    }
                    else if (bncval == 0f)// 处于平滑结束
                    {
                        endval = Math.Min(1f - startval, endval);
                    }

                    if (firstflag == false)
                        SetBehaviorTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothEndBox.DecreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorSmoothEndBox.LargeChange;
                var minval = behaviorSmoothEndBox.MinValue;
                var maxval = behaviorSmoothEndBox.MaxValue;
                if (ispress) change = behaviorSmoothEndBox.SmallChange;

                foreach (var bhv in BehaviorRange)
                {
                    var tim = bhv.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    endval = Math.Max(minval, endval - change);
                    startval = Math.Min(1f - endval, startval);

                    if (firstflag == false)
                        SetBehaviorTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }

            };

            behaviorBounceEndBox.DecreaseRelValue += (sender, arg) =>
            {
                var firstflag = false;

                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorBounceEndBox.LargeChange;
                var minval = behaviorBounceEndBox.MinValue;
                var maxval = behaviorBounceEndBox.MaxValue;
                if (ispress) change = behaviorBounceEndBox.SmallChange;

                foreach (var bhv in BehaviorRange)
                {
                    var tim = bhv.Timing;
                    var startval = tim.Accelerate;
                    var endval = tim.Decelerate;
                    var bncval = tim.BounceEndIntensity;

                    bncval = Math.Max(minval, bncval - change);
                    startval = Math.Min(1f - bncval, startval);

                    if (firstflag == false)
                        SetBehaviorTimingSmoothUI(startval, endval, bncval);
                    firstflag = true;

                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };
            #endregion



            behaviorSmoothStartBar.ValueChanged += (sender, arg) =>
            {
                if (behaviorBarGroupEventFlag) return;
                var startval = (float)behaviorSmoothStartBar.Value;
                var endval = (float)behaviorSmoothEndBar.Value;
                var bncval = (float)behaviorBounceEndBar.Value;
                if (endval == 0f) // 处于弹性结束
                {
                    bncval = Math.Min(1f - startval, bncval);
                    behaviorBounceEndBar.Value = bncval;
                }
                else if (bncval == 0f)// 处于平滑结束
                {
                    endval = Math.Min(1f - startval, endval);
                    behaviorSmoothEndBar.Value = endval;
                }

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorSmoothEndBar.ValueChanged += (sender, arg) =>
            {
                if (behaviorBarGroupEventFlag) return;
                var endval = (float)behaviorSmoothEndBar.Value;
                var startval = (float)behaviorSmoothStartBar.Value;
                var bncval = 0f;

                startval = Math.Min(1f - endval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };

            behaviorBounceEndBar.ValueChanged += (sender, arg) =>
            {
                if (behaviorBarGroupEventFlag) return;
                var bncval = (float)behaviorBounceEndBar.Value;
                var endval = 0f;
                var startval = (float)behaviorSmoothStartBar.Value;


                startval = Math.Min(1f - bncval, startval);

                SetBehaviorTimingSmoothUI(startval, endval, bncval); // 重新更新UI。

                foreach (var bhv in BehaviorRange)
                {
                    bhv.Timing.Accelerate = startval;
                    bhv.Timing.Decelerate = endval;
                    bhv.Timing.BounceEndIntensity = bncval;
                }
            };
            #endregion

            #region behaviorAdditiveCheckBox

            behaviorAdditiveCheckBox.Checked += (s, e) =>
            {
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Additive = PPT.MsoAnimAdditive.msoAnimAdditiveAddSum;
                }
            };

            behaviorAdditiveCheckBox.Checked += (s, e) =>
            {
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Additive = PPT.MsoAnimAdditive.msoAnimAdditiveAddBase;
                }
            };

            #endregion

            #region behaviorAccumulateCheckBox

            behaviorAccumulateCheckBox.Checked += (s, e) =>
            {
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Accumulate = PPT.MsoAnimAccumulate.msoAnimAccumulateAlways;
                }
            };

            behaviorAccumulateCheckBox.Checked += (s, e) =>
            {
                foreach (var bhv in BehaviorRange)
                {
                    bhv.Accumulate = PPT.MsoAnimAccumulate.msoAnimAccumulateNone;
                }
            };
            #endregion

        }

        private void InitBehaviorInformationUI()
        {
            #region anim type to UI
            _animTypeUIDic = new Dictionary<PPT.MsoAnimType, FrameworkElement>();
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeProperty, behaviorInformationPropertyGrid);
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeSet, behaviorInformationSetGrid);
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeColor, behaviorInformationColorGrid);
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeScale, behaviorInformationScaleGrid);
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeRotation, behaviorInformationRotationGrid);
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeFilter, behaviorInformationFilterGrid);
            _animTypeUIDic.Add(PPT.MsoAnimType.msoAnimTypeMotion, behaviorInformationMotionGrid);
            #endregion

            #region property data

            var propertyComboBoxItemSource = AnimEffect.GetAvaliableAnimPropertyTypeList();
            var visibilityComboBoxItemSource = new string[] { "不可见", "可见", };

            #endregion

            #region set

            behaviorInformationSetNonVisibilityTextBox.ButtonText1 = "↑";
            behaviorInformationSetNonVisibilityTextBox.ButtonText2 = "↓";
            behaviorInformationSetNonVisibilityTextBox.MinValue = 0f;
            behaviorInformationSetNonVisibilityTextBox.MaxValue = 65535f;
            behaviorInformationSetNonVisibilityTextBox.SmallChange = 0.01f;
            behaviorInformationSetNonVisibilityTextBox.LargeChange = 0.05f;

            behaviorInformationSetPropertyComboBox.ItemsSource = propertyComboBoxItemSource;
            behaviorInformationSetVisibilityComboBox.ItemsSource = visibilityComboBoxItemSource;

            behaviorInformationSetPropertyComboBox.SelectionChanged += (s, e) =>
            {
                var propertyType = AnimEffect.GetPropertyTypeFromName(behaviorInformationSetPropertyComboBox.SelectedItem as string);
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeSet)
                    {

                        dynamic tovalue = bhv.SetEffect.To;
                        float truevalue = 0f;
                        if (tovalue is string)
                            truevalue = tovalue == "visible" ? 1f : 0f;
                        else if (tovalue is int)
                            truevalue = tovalue == 1 ? 1f : 0f;
                        else
                            truevalue = tovalue == null ? 0f : (float)tovalue;

                        if (propertyType == PPT.MsoAnimProperty.msoAnimVisibility) // 可见性
                        {
                            bhv.SetEffect.Property = propertyType;
                            bhv.SetEffect.To = truevalue >= 1f ? (int)1 : (int)0;
                        }
                        else
                        {
                            bhv.SetEffect.Property = propertyType;
                            bhv.SetEffect.To = truevalue;
                        }

                    }


                }
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationSetVisibilityComboBox.SelectionChanged += (s, e) =>
            {
                var visibility = behaviorInformationSetVisibilityComboBox.SelectedIndex;
                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeSet)
                        bhv.SetEffect.To = visibility;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationSetNonVisibilityTextBox.LostFocus += (s, e) =>
            {
                var value = behaviorInformationSetNonVisibilityTextBox.Text.ToFloat();
                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeSet)
                        bhv.SetEffect.To = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationSetNonVisibilityTextBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorInformationSetNonVisibilityTextBox.LargeChange;
                if (ispress) change = behaviorInformationSetNonVisibilityTextBox.SmallChange;
                var value = behaviorInformationSetNonVisibilityTextBox.Text.ToFloat();
                var min = behaviorInformationSetNonVisibilityTextBox.MinValue;
                var max = behaviorInformationSetNonVisibilityTextBox.MaxValue;

                value = Math.Min(value + change, max);

                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeSet)
                        bhv.SetEffect.To = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationSetNonVisibilityTextBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorInformationSetNonVisibilityTextBox.LargeChange;
                if (ispress) change = behaviorInformationSetNonVisibilityTextBox.SmallChange;
                var value = behaviorInformationSetNonVisibilityTextBox.Text.ToFloat();
                var min = behaviorInformationSetNonVisibilityTextBox.MinValue;
                var max = behaviorInformationSetNonVisibilityTextBox.MaxValue;

                value = Math.Max(value - change, min);

                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeSet)
                        bhv.SetEffect.To = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());

            };

            #endregion

            #region property

            behaviorInformationPropertyNonVisibilityFromTextBox.ButtonText1 = "↑";
            behaviorInformationPropertyNonVisibilityFromTextBox.ButtonText2 = "↓";
            behaviorInformationPropertyNonVisibilityFromTextBox.MinValue = 0f;
            behaviorInformationPropertyNonVisibilityFromTextBox.MaxValue = 65535f;
            behaviorInformationPropertyNonVisibilityFromTextBox.SmallChange = 0.01f;
            behaviorInformationPropertyNonVisibilityFromTextBox.LargeChange = 0.05f;

            behaviorInformationPropertyNonVisibilityToTextBox.ButtonText1 = "↑";
            behaviorInformationPropertyNonVisibilityToTextBox.ButtonText2 = "↓";
            behaviorInformationPropertyNonVisibilityToTextBox.MinValue = 0f;
            behaviorInformationPropertyNonVisibilityToTextBox.MaxValue = 65535f;
            behaviorInformationPropertyNonVisibilityToTextBox.SmallChange = 0.01f;
            behaviorInformationPropertyNonVisibilityToTextBox.LargeChange = 0.05f;

            behaviorInformationPropertyPropertyComboBox.ItemsSource = propertyComboBoxItemSource;
            behaviorInformationPropertyVisibilityFromComboBox.ItemsSource = visibilityComboBoxItemSource;
            behaviorInformationPropertyVisibilityToComboBox.ItemsSource = visibilityComboBoxItemSource;

            behaviorInformationPropertyPropertyComboBox.SelectionChanged += (s, e) =>
            {
                var propertyType = AnimEffect.GetPropertyTypeFromName(behaviorInformationPropertyPropertyComboBox.SelectedItem as string);
                var bhvrange = BehaviorRange;
                foreach (var bhv in bhvrange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                    {

                        dynamic tovalue = bhv.PropertyEffect.To;
                        dynamic fromvalue = bhv.PropertyEffect.From;
                        float truefromvalue = 0f, truetovalue = 0f;

                        if (fromvalue is string)
                            truefromvalue = fromvalue == "visible" ? 1f : 0f;
                        else if (fromvalue is int)
                            truefromvalue = fromvalue == 1 ? 1f : 0f;
                        else
                            truefromvalue = fromvalue == null ? 0f : (float)fromvalue;

                        if (tovalue is string)
                            truetovalue = tovalue == "visible" ? 1f : 0f;
                        else if (tovalue is int)
                            truetovalue = tovalue == 1 ? 1f : 0f;
                        else
                            truetovalue = tovalue == null ? 0f : (float)tovalue;


                        if (propertyType == PPT.MsoAnimProperty.msoAnimVisibility) // 可见性
                        {
                            bhv.PropertyEffect.Property = propertyType;
                            bhv.PropertyEffect.From = truefromvalue >= 1f ? (int)1 : (int)0;
                            bhv.PropertyEffect.To = truetovalue >= 1f ? (int)1 : (int)0;
                        }
                        else
                        {
                            bhv.PropertyEffect.Property = propertyType;
                            bhv.PropertyEffect.From = truefromvalue;
                            bhv.PropertyEffect.To = truetovalue;
                        }

                    }


                }
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyVisibilityFromComboBox.SelectionChanged += (s, e) =>
            {
                var visibility = behaviorInformationPropertyVisibilityFromComboBox.SelectedIndex;
                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.From = visibility;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyNonVisibilityFromTextBox.LostFocus += (s, e) =>
            {
                var value = behaviorInformationPropertyNonVisibilityFromTextBox.Text.ToFloat();
                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.From = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyNonVisibilityFromTextBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorInformationPropertyNonVisibilityFromTextBox.LargeChange;
                if (ispress) change = behaviorInformationPropertyNonVisibilityFromTextBox.SmallChange;
                var value = behaviorInformationPropertyNonVisibilityFromTextBox.Text.ToFloat();
                var min = behaviorInformationPropertyNonVisibilityFromTextBox.MinValue;
                var max = behaviorInformationPropertyNonVisibilityFromTextBox.MaxValue;

                value = Math.Min(value + change, max);

                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.From = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyNonVisibilityFromTextBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorInformationPropertyNonVisibilityFromTextBox.LargeChange;
                if (ispress) change = behaviorInformationPropertyNonVisibilityFromTextBox.SmallChange;
                var value = behaviorInformationPropertyNonVisibilityFromTextBox.Text.ToFloat();
                var min = behaviorInformationPropertyNonVisibilityFromTextBox.MinValue;
                var max = behaviorInformationPropertyNonVisibilityFromTextBox.MaxValue;

                value = Math.Max(value - change, min);

                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.From = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());

            };

            behaviorInformationPropertyVisibilityToComboBox.SelectionChanged += (s, e) =>
            {
                var visibility = behaviorInformationPropertyVisibilityToComboBox.SelectedIndex;
                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.To = visibility;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyNonVisibilityToTextBox.LostFocus += (s, e) =>
            {
                var value = behaviorInformationPropertyNonVisibilityToTextBox.Text.ToFloat();
                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.To = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyNonVisibilityToTextBox.IncreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorInformationPropertyNonVisibilityToTextBox.LargeChange;
                if (ispress) change = behaviorInformationPropertyNonVisibilityToTextBox.SmallChange;
                var value = behaviorInformationPropertyNonVisibilityToTextBox.Text.ToFloat();
                var min = behaviorInformationPropertyNonVisibilityToTextBox.MinValue;
                var max = behaviorInformationPropertyNonVisibilityToTextBox.MaxValue;

                value = Math.Min(value + change, max);

                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.To = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyNonVisibilityToTextBox.DecreaseAbsValue += (s, e) =>
            {
                var ispress = Keyboard.IsKeyDown(Key.LeftCtrl);
                var change = behaviorInformationPropertyNonVisibilityToTextBox.LargeChange;
                if (ispress) change = behaviorInformationPropertyNonVisibilityToTextBox.SmallChange;
                var value = behaviorInformationPropertyNonVisibilityToTextBox.Text.ToFloat();
                var min = behaviorInformationPropertyNonVisibilityToTextBox.MinValue;
                var max = behaviorInformationPropertyNonVisibilityToTextBox.MaxValue;

                value = Math.Max(value - change, min);

                foreach (var bhv in BehaviorRange)
                {
                    if (bhv.Type == PPT.MsoAnimType.msoAnimTypeProperty)
                        bhv.PropertyEffect.To = value;
                }
                var bhvrange = BehaviorRange;
                if (bhvrange.Count() != 0)
                    ShowBehaviorInformationUI(bhvrange.First());
            };

            behaviorInformationPropertyKeyPointsButton.Click += (s, e) =>
              {
                  var control = PopupWindowManager.KeyPointFrameEditorWindow.Content as KeyPointFrameEditorControl;
                  var propertyType = AnimEffect.GetPropertyTypeFromName(behaviorInformationPropertyPropertyComboBox.SelectedItem as string);

                  var effect = EffectRange.First();
                  var behavior = BehaviorRange.First();

                  if (effect == null || behavior == null || behavior.Type != PPT.MsoAnimType.msoAnimTypeProperty) return;

                  var propertyEffect = behavior.PropertyEffect;
                  var newpoints = new List<KeyPointInformation>();

                  foreach (PPT.AnimationPoint point in propertyEffect.Points)
                  {
                      newpoints.Add(new KeyPointInformation(point.Time, point.Value, point.Formula));
                  }

                  control.Load(propertyType, propertyEffect.Points, newpoints, effect.Shape);
                  PopupWindowManager.KeyPointFrameEditorWindow.ShowDialog();
              };

            #endregion

        }

        #endregion

        #region readonly properties
        private IEnumerable<PPT.Effect> EffectRange => from PPT.Effect eff in effectList.SelectedItems select eff;

        private IEnumerable<PPT.AnimationBehavior> BehaviorRange => from PPT.AnimationBehavior bhv in behaviorList.SelectedItems select bhv;

        //private PPT.Effect FirstEffectInSelection
        //{
        //    get
        //    {
        //        return EffectRange.FirstOrDefault();
        //    }
        //}

        #endregion

        #region main ui

        // 预览动画。
        private void PreviewAnimation_Click(object sender, RoutedEventArgs e)
        {
            var cmd = Command.CommandManager.GetCommand("动画预览");
            cmd.Excute(CoreManipulator.App);
        }

        // 刷新窗格。
        private void AnButton_Click(object sender, RoutedEventArgs e)
        {
            RefreshTaskPane();
        }

        // 更新窗格栏。
        public void RefreshTaskPane()
        {
            this.Dispatcher.Invoke(() =>
            {
                try
                {
                    var slide = CoreManipulator.GetSlideInGeneralOccassion();
                    var shapeRange = CoreManipulator.GetShapeRange();
                    behaviorList.ItemsSource = null;
                    if (slide != null)
                    {
                        var effects = from PPT.Effect eff
                                      in slide.TimeLine.MainSequence
                                      select eff;

                        if (effects.Count() != 0)
                        {
                            var firsteff = effects.First();
                            var bhvs = from PPT.AnimationBehavior bhv in firsteff.Behaviors select bhv;

                            effectList.ItemsSource = effects;
                            effectList.SelectedIndex = 0;
                            UpdateEffectTimingUI(effects);

                            behaviorList.ItemsSource = bhvs;
                            behaviorList.SelectedIndex = 0;
                            UpdateBehaviorTimingUI(bhvs);

                            effectTimingGrid.Visibility = Visibility.Visible;
                            behaviorTimingGrid.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            effectTimingGrid.Visibility = Visibility.Hidden;
                            behaviorTimingGrid.Visibility = Visibility.Hidden;
                            effectList.ItemsSource = null;
                            behaviorList.ItemsSource = null;
                        }


                    }
                    else if (shapeRange != null)
                    {
                        var shape = shapeRange[1];
                        var effects = from PPT.Effect eff
                                      in slide.TimeLine.MainSequence
                                      where eff.Shape == shape
                                      select eff;


                        if (effects.Count() != 0)
                        {
                            var firsteff = effects.First();
                            var bhvs = from PPT.AnimationBehavior bhv in firsteff.Behaviors select bhv;

                            effectList.ItemsSource = effects;
                            effectList.SelectedIndex = 0;
                            UpdateEffectTimingUI(effects);

                            behaviorList.ItemsSource = bhvs;
                            behaviorList.SelectedIndex = 0;
                            UpdateBehaviorTimingUI(bhvs);

                            effectTimingGrid.Visibility = Visibility.Visible;
                            behaviorTimingGrid.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            effectTimingGrid.Visibility = Visibility.Hidden;
                            behaviorTimingGrid.Visibility = Visibility.Hidden;
                        }


                    }

                }
                catch (Exception ex)
                {
                    string str = ex.StackTrace;
                    System.Windows.Forms.MessageBox.Show(str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1));
                }



                // TODO
            });

        }

        #endregion

        #region effect list
        /// <summary>
        /// 选中更改时。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void effectList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                var effrange = EffectRange;

                UpdateEffectTimingUI(effrange);

                if (effrange.Count() != 0)
                {
                    behaviorList.ItemsSource = effrange.First().Behaviors;
                    behaviorList.SelectedIndex = 0;
                }
            }
            catch (Exception)
            {
            }
            
        }

        #endregion

        #region effect timing

        // 类型与前端 ComboBox 下标的转换，1 为之前，2 为之后，0 为鼠标单击
        private int TriggerTypeToUIIndex(PPT.MsoAnimTriggerType triggerType)
        {
            switch (triggerType)
            {
                case PPT.MsoAnimTriggerType.msoAnimTriggerMixed:
                    return 1;
                case PPT.MsoAnimTriggerType.msoAnimTriggerNone:
                    return 1;
                case PPT.MsoAnimTriggerType.msoAnimTriggerOnPageClick:
                    return 0;
                case PPT.MsoAnimTriggerType.msoAnimTriggerWithPrevious:
                    return 1;
                case PPT.MsoAnimTriggerType.msoAnimTriggerAfterPrevious:
                    return 2;
                case PPT.MsoAnimTriggerType.msoAnimTriggerOnShapeClick:
                    return 0;
                case PPT.MsoAnimTriggerType.msoAnimTriggerOnMediaBookmark:
                    return 1;
                default:
                    return 1;
            }
        }

        // 设置计时效果
        private void SetEffectTimingUI(PPT.Timing tim, bool isMergeMode)
        {
            float delay = 0;
            float dur = 0;
            int repeat = 1;
            float smstart = 0;
            float smend = 0;
            float bounce = 0;
            bool autoReverse = false;
            int triggerTypeIndex = 1;// 0 单击，1 之前，2 之后

            if (tim != null)
            {
                delay = tim.TriggerDelayTime;
                dur = tim.Duration;
                repeat = tim.RepeatCount;
                smstart = tim.Accelerate;
                smend = tim.Decelerate;
                bounce = tim.BounceEndIntensity;
                autoReverse = tim.AutoReverse == Microsoft.Office.Core.MsoTriState.msoTrue;
                triggerTypeIndex = TriggerTypeToUIIndex(tim.TriggerType);
            }

            // 延迟和时长。
            effectDelayBox.Text = Math.Round(delay, 4).ToString();
            effectDurationBox.Text = Math.Round(dur, 4).ToString();

            // 重复次数
            if (repeat < 0)
                effectRepeatBox.Text = "999";
            else
                effectRepeatBox.Text = repeat.ToString();

            SetEffectTimingSmoothUI(smstart, smend, bounce);

            // 自动翻转
            effectAutoReverseCheckBox.IsChecked = autoReverse;

            effectTriggerTypeComboBox.SelectedIndex = triggerTypeIndex;

            // 合并模式。
            effectDelayBox.IsMergedMode = isMergeMode;
            effectDurationBox.IsMergedMode = isMergeMode;
            effectSmoothStartBox.IsMergedMode = isMergeMode;
            effectSmoothEndBox.IsMergedMode = isMergeMode;
            effectBounceEndBox.IsMergedMode = isMergeMode;
        }

        // 单独更新平滑控件的外观。
        private void SetEffectTimingSmoothUI(double smoothStart, double smoothEnd, double bounce)
        {
            effectBarGroupEventFlag = true; // 开启禁止，禁止在此时触发事件。
            SetEffectTimingSmoothSlideBar(smoothStart, smoothEnd, bounce);
            SetEffectTimingSmoothTextBox(smoothStart, smoothEnd, bounce);
            effectBarGroupEventFlag = false;
        }

        private void SetEffectTimingSmoothSlideBar(double smoothStart, double smoothEnd, double bounce)
        {
            effectSmoothStartBar.Value = smoothStart;
            effectSmoothEndBar.Value = smoothEnd;
            effectBounceEndBar.Value = bounce;
        }

        private void SetEffectTimingSmoothTextBox(double smoothStart, double smoothEnd, double bounce)
        {
            effectSmoothStartBox.Text = Math.Round(smoothStart, 4).ToString();
            effectSmoothEndBox.Text = Math.Round(smoothEnd, 4).ToString();
            effectBounceEndBox.Text = Math.Round(bounce, 4).ToString();
        }

        /// <summary>
        /// 清空效果UI。
        /// </summary>
        private void ClearEffectTimingUI()
        {
            effectTimingGrid.Visibility = Visibility.Hidden;
            effectDelayBox.Text = "";
            effectDurationBox.Text = "";
            effectRepeatBox.Text = "";
            effectSmoothStartBar.Value = 0d;
            effectSmoothEndBar.Value = 0d;
            effectBounceEndBar.Value = 0d;
        }

        /// <summary>
        /// 显示效果UI。
        /// </summary>
        private void ShowEffectTimingUI(PPT.Timing tim, bool isMergeMode)
        {
            effectTimingGrid.Visibility = Visibility.Visible;
            SetEffectTimingUI(tim, isMergeMode);
        }


        /// <summary>
        /// 载入效果集合对象
        /// </summary>
        private void UpdateEffectTimingUI(IEnumerable<PPT.Effect> range)
        {
            if (range == null)
            {
                ClearEffectTimingUI();
            }
            else
            {
                var count = range.Count();
                if (count == 0)
                {
                    ClearEffectTimingUI();
                }
                else if (count == 1) // 单独
                {
                    var eff = range.First();
                    var tim = eff.Timing;
                    ShowEffectTimingUI(tim, true);
                }
                else // 多选
                {
                    var eff = range.First();
                    var tim = eff.Timing;
                    ShowEffectTimingUI(tim, false);
                }
            }
        }


        #endregion

        #region behavior list

        private void UpdateBehaviorList()
        {
            var effrange = EffectRange;
            var tempIndex = behaviorList.SelectedIndex;
            behaviorList.ItemsSource = from PPT.AnimationBehavior bhv in effrange.First().Behaviors select bhv;
            behaviorList.SelectedIndex = 0;
        }

        /// <summary>
        /// 行为的列表发生更改时。
        /// </summary>
        private void behaviorList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var bhvrange = BehaviorRange;
            UpdateBehaviorTimingUI(bhvrange);
            if (bhvrange.Count() != 0)
            {
                var firstbhv = bhvrange.First();
                ShowBehaviorInformationUI(firstbhv);
            }
        }

        #endregion

        #region behavior timing

        private void SetBehaviorTimingUI(PPT.AnimationBehavior bhv, bool isMergeMode)
        {
            try
            {
                SetBehaviorTimingUI(bhv.Timing, isMergeMode);
                behaviorAdditiveCheckBox.IsChecked = bhv.Additive == PPT.MsoAnimAdditive.msoAnimAdditiveAddSum;
                behaviorAccumulateCheckBox.IsChecked = bhv.Accumulate == PPT.MsoAnimAccumulate.msoAnimAccumulateAlways;

            }
            catch
            {

            }
        }


        // 设置计时效果
        private void SetBehaviorTimingUI(PPT.Timing tim, bool isMergeMode)
        {
            try
            {
                float delay = 0;
                float dur = 0;
                int repeat = 1;
                float smstart = 0;
                float smend = 0;
                float bounce = 0;
                // bool autoReverse = false;

                if (tim != null)
                {
                    delay = tim.TriggerDelayTime;
                    dur = tim.Duration;
                    repeat = tim.RepeatCount;
                    smstart = tim.Accelerate;
                    smend = tim.Decelerate;
                    bounce = tim.BounceEndIntensity;
                    // autoReverse = tim.AutoReverse == Microsoft.Office.Core.MsoTriState.msoTrue;
                }

                // 延迟和时长。
                behaviorDelayBox.Text = Math.Round(delay, 4).ToString();
                behaviorDurationBox.Text = Math.Round(dur, 4).ToString();

                // 重复次数
                if (repeat < 0)
                    behaviorRepeatBox.Text = "999";
                else
                    behaviorRepeatBox.Text = repeat.ToString();

                SetBehaviorTimingSmoothUI(smstart, smend, bounce);

                //// 自动翻转
                //behaviorAutoReverseCheckBox.IsChecked = autoReverse;


                // 合并模式。
                behaviorDelayBox.IsMergedMode = isMergeMode;
                behaviorDurationBox.IsMergedMode = isMergeMode;
                behaviorSmoothStartBox.IsMergedMode = isMergeMode;
                behaviorSmoothEndBox.IsMergedMode = isMergeMode;
                behaviorBounceEndBox.IsMergedMode = isMergeMode;
            }
            catch
            {

            }
           
        }

        // 单独更新平滑控件的外观。
        private void SetBehaviorTimingSmoothUI(double smoothStart, double smoothEnd, double bounce)
        {
            behaviorBarGroupEventFlag = true; // 开启禁止，禁止在此时触发事件。
            SetBehaviorTimingSmoothSlideBar(smoothStart, smoothEnd, bounce);
            SetBehaviorTimingSmoothTextBox(smoothStart, smoothEnd, bounce);
            behaviorBarGroupEventFlag = false;
        }

        private void SetBehaviorTimingSmoothSlideBar(double smoothStart, double smoothEnd, double bounce)
        {
            behaviorSmoothStartBar.Value = smoothStart;
            behaviorSmoothEndBar.Value = smoothEnd;
            behaviorBounceEndBar.Value = bounce;
        }

        private void SetBehaviorTimingSmoothTextBox(double smoothStart, double smoothEnd, double bounce)
        {
            behaviorSmoothStartBox.Text = Math.Round(smoothStart, 4).ToString();
            behaviorSmoothEndBox.Text = Math.Round(smoothEnd, 4).ToString();
            behaviorBounceEndBox.Text = Math.Round(bounce, 4).ToString();
        }

        /// <summary>
        /// 清空效果UI。
        /// </summary>
        private void ClearBehaviorTimingUI()
        {
            behaviorTimingGrid.Visibility = Visibility.Hidden;
            behaviorDelayBox.Text = "";
            behaviorDurationBox.Text = "";
            behaviorRepeatBox.Text = "";
            behaviorSmoothStartBar.Value = 0d;
            behaviorSmoothEndBar.Value = 0d;
            behaviorBounceEndBar.Value = 0d;
        }

        /// <summary>
        /// 显示效果UI。
        /// </summary>
        private void ShowBehaviorTimingUI(PPT.Timing tim, bool isMergeMode)
        {
            behaviorTimingGrid.Visibility = Visibility.Visible;
            SetBehaviorTimingUI(tim, isMergeMode);
        }

        private void ShowBehaviorTimingUI(PPT.AnimationBehavior bhv, bool isMergeMode)
        {
            behaviorTimingGrid.Visibility = Visibility.Visible;
            SetBehaviorTimingUI(bhv, isMergeMode);
        }


        /// <summary>
        /// 载入效果集合对象
        /// </summary>
        private void UpdateBehaviorTimingUI(IEnumerable<PPT.AnimationBehavior> range)
        {
            if (range == null)
            {
                ClearBehaviorTimingUI();
            }
            else
            {
                var count = range.Count();
                if (count == 0)
                {
                    ClearBehaviorTimingUI();
                }
                else if (count == 1) // 单独
                {
                    var bhv = range.First();
                    ShowBehaviorTimingUI(bhv, true);
                }
                else // 多选
                {
                    var bhv = range.First();
                    ShowBehaviorTimingUI(bhv, false);
                }
            }
        }


        #endregion

        #region behavior info

        // 由于可见度的值仅仅为 0 和 1，为此需要对其分类讨论。
        private AnimPropertyType GetAnimPropertyType(PPT.SetEffect effect)
        {
            if (effect.Property == PPT.MsoAnimProperty.msoAnimVisibility) return AnimPropertyType.Visibility;
            else if (effect.Property == PPT.MsoAnimProperty.msoAnimColor) return AnimPropertyType.Color;
            return AnimPropertyType.Other;
        }

        private AnimPropertyType GetAnimPropertyType(PPT.PropertyEffect effect)
        {
            if (effect.Property == PPT.MsoAnimProperty.msoAnimVisibility) return AnimPropertyType.Visibility;
            else if (effect.Property == PPT.MsoAnimProperty.msoAnimColor) return AnimPropertyType.Color;
            return AnimPropertyType.Other;
        }

        /// <summary>
        /// 设置行为的具体面板。
        /// </summary>
        private void SelectBehaviorInformationUI(PPT.MsoAnimType animType)
        {
            foreach (var pair in _animTypeUIDic)
            {
                var type = pair.Key;
                var ele = pair.Value;
                if (type == animType)
                    ele.Visibility = Visibility.Visible;
                else
                    ele.Visibility = Visibility.Hidden;
            }
        }

        // TODO 显示行为的信息 UI。
        private void ShowBehaviorInformationUI(PPT.AnimationBehavior behavior)
        {
            switch (behavior.Type)
            {
                case PPT.MsoAnimType.msoAnimTypeMotion:
                    
                   
                    break;
                case PPT.MsoAnimType.msoAnimTypeColor:
                    
                    break;
                case PPT.MsoAnimType.msoAnimTypeScale:
                    
                    break;
                case PPT.MsoAnimType.msoAnimTypeRotation:
  
                    break;
                case PPT.MsoAnimType.msoAnimTypeProperty:
                    ShowBehaviorInformationUI(behavior.PropertyEffect);
                    break;
                case PPT.MsoAnimType.msoAnimTypeFilter:
                    // ShowBehaviorInformationUI(behavior);
                    break;
                case PPT.MsoAnimType.msoAnimTypeSet:
                    ShowBehaviorInformationUI(behavior.SetEffect);
                    break;
                default:
                    break;
            }
        }

        private void ShowBehaviorInformationUI(PPT.PropertyEffect effect)
        {
            SelectBehaviorInformationUI(PPT.MsoAnimType.msoAnimTypeProperty);
            foreach (string item in behaviorInformationPropertyPropertyComboBox.Items)
            {
                if (effect.Property == AnimEffect.GetPropertyTypeFromName(item))
                {
                    behaviorInformationPropertyPropertyComboBox.SelectedItem = item;
                    break;
                }
            }

            switch (GetAnimPropertyType(effect))
            {
                case AnimPropertyType.Visibility:
                    {
                        behaviorInformationPropertyVisibilityFromComboBox.Visibility = Visibility.Visible;
                        behaviorInformationPropertyVisibilityToComboBox.Visibility = Visibility.Visible;
                        behaviorInformationPropertyNonVisibilityFromTextBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyNonVisibilityToTextBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyColorFromBorder.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyColorToBorder.Visibility = Visibility.Hidden;

                        if ((int)effect.From == 0)
                            behaviorInformationPropertyVisibilityFromComboBox.SelectedIndex = 0;
                        else
                            behaviorInformationPropertyVisibilityFromComboBox.SelectedIndex = 1;

                        if ((int)effect.To == 0)
                            behaviorInformationPropertyVisibilityToComboBox.SelectedIndex = 0;
                        else
                            behaviorInformationPropertyVisibilityToComboBox.SelectedIndex = 1;

                    }

                    break;
                case AnimPropertyType.Color:
                    {
                        behaviorInformationPropertyVisibilityFromComboBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyNonVisibilityFromTextBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyColorFromBorder.Visibility = Visibility.Visible;
                        behaviorInformationPropertyVisibilityToComboBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyNonVisibilityToTextBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyColorToBorder.Visibility = Visibility.Visible;
                    }

                    break;
                case AnimPropertyType.Other:
                    {
                        behaviorInformationPropertyVisibilityFromComboBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyNonVisibilityFromTextBox.Visibility = Visibility.Visible;
                        behaviorInformationPropertyColorFromBorder.Visibility = Visibility.Hidden;

                        behaviorInformationPropertyNonVisibilityFromTextBox.Text = effect.From == null ? "0" : ((float)(effect.From)).ToString();

                        behaviorInformationPropertyVisibilityToComboBox.Visibility = Visibility.Hidden;
                        behaviorInformationPropertyNonVisibilityToTextBox.Visibility = Visibility.Visible;
                        behaviorInformationPropertyColorToBorder.Visibility = Visibility.Hidden;

                        behaviorInformationPropertyNonVisibilityToTextBox.Text = effect.To == null ? "0" : ((float)(effect.To)).ToString();
                    }

                    break;
                default:
                    break;
            }

        }

        private void ShowBehaviorInformationUI(PPT.SetEffect effect)
        {
            SelectBehaviorInformationUI(PPT.MsoAnimType.msoAnimTypeSet);
            foreach (string item in behaviorInformationSetPropertyComboBox.Items)
            {
                if (effect.Property == AnimEffect.GetPropertyTypeFromName(item))
                {
                    behaviorInformationSetPropertyComboBox.SelectedItem = item;
                    break;
                }
            }

            switch (GetAnimPropertyType(effect))
            {
                case AnimPropertyType.Visibility:
                    {
                        behaviorInformationSetVisibilityComboBox.Visibility = Visibility.Visible;
                        behaviorInformationSetNonVisibilityTextBox.Visibility = Visibility.Hidden;
                        behaviorInformationSetColorBorder.Visibility = Visibility.Hidden;

                        if ((int)effect.To == 0)
                            behaviorInformationSetVisibilityComboBox.SelectedIndex = 0;
                        else
                            behaviorInformationSetVisibilityComboBox.SelectedIndex = 1;

                    }

                    break;
                case AnimPropertyType.Color:
                    {
                        behaviorInformationSetVisibilityComboBox.Visibility = Visibility.Hidden;
                        behaviorInformationSetNonVisibilityTextBox.Visibility = Visibility.Hidden;
                        behaviorInformationSetColorBorder.Visibility = Visibility.Visible;
                    }

                    break;
                case AnimPropertyType.Other:
                    {
                        behaviorInformationSetVisibilityComboBox.Visibility = Visibility.Hidden;
                        behaviorInformationSetNonVisibilityTextBox.Visibility = Visibility.Visible;
                        behaviorInformationSetColorBorder.Visibility = Visibility.Hidden;

                        behaviorInformationSetNonVisibilityTextBox.Text = ((float)(effect.To)).ToString();
                    }

                    break;
                default:
                    break;
            }

        }


        #endregion

        #region 鼠标滚轮相关
        private void scrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {

        }

        private void scrollViewer1_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
            eventArg.RoutedEvent = UIElement.MouseWheelEvent;
            eventArg.Source = e.Source;

            ScrollViewer scv = (ScrollViewer)sender;
            scv.RaiseEvent(eventArg);
            e.Handled = true;
        }

        private void behaviorList_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            // 直接跳转至上述scrollViewer的滚动事件
            scrollViewer_PreviewMouseWheel(scrollViewer1, e);
        }

        private void scrollViewer2_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
            eventArg.RoutedEvent = UIElement.MouseWheelEvent;
            eventArg.Source = e.Source;

            ScrollViewer scv = (ScrollViewer)sender;
            scv.RaiseEvent(eventArg);
            e.Handled = true;

        }

        private void effectList_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            // 直接跳转至上述scrollViewer的滚动事件
            scrollViewer_PreviewMouseWheel(scrollViewer2, e);
        }
        #endregion

    }
}
